#@layoutMain()
#define mainMessage()

<fieldset class="layui-elem-field layui-field-title">
	<legend>
		评论管理
	</legend>
</fieldset>
<div style="padding-left: 10px;">
	<div>
		<div style="padding: 20px">
			<div class="layui-form">
				<div class="layui-inline">
					<label class="layui-form-label">评论内容：</label>
					<div class="layui-input-inline">
						<input type="text" id="s_name" name="s_name" style="width: 300px" placeholder="请输入"
						autocomplete="off" class="layui-input" onkeydown="if(event.keyCode==13) search()">
					</div>
				</div>
				&nbsp;&nbsp;
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-list" lay-submit="" onclick="search()"
					lay-filter="LAY-app-contlist-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn">
						</i>
					</button>
				</div>
			</div>
		</div>

	</div>
	<div>
		<table class="layui-hide" id="commentListTable"></table>
	</div>
</div>

#end

#define js()

<script type="text/html" id="switchTpl">
	<!-- 这里的 checked 的状态只是演示 -->
	<input type="checkbox" name="{{d.cid}}" value="{{d.state}}" lay-skin="switch" lay-filter="hotSwitch" lay-text="&nbsp;是&nbsp;|&nbsp;否&nbsp;" {{ d.state == 1 ? 'checked' : '' }}>
</script>

<script>
layui.use(['element','form','table'], function(){
    var form=layui.form;
	  var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
	  $ = layui.jquery; // 使用jquery
	  table = layui.table;
	  
	  table.render({
	    elem: '#commentListTable'
	    ,url:'/admin/comment/commentListTable'
	    ,id: 'commentList'
	    ,cols: [[
			{field:'cid', width:80, title: '编号', sort: true,align:'center'}
	      ,{field:'content', width:340, title: '评论内容'}
	      ,{field:'comment_date', width:180, title: '发布日期', sort: true,align:'center'}
	      ,{field:'name', width:260, title: '文章标题',align:'center',sort: true}
	      ,{field:'username', width:160, title: '用户名',align:'center',sort: true}
	      ,{field:'state', width:120, title: '审核状态',align:'center',templet:formatState,sort: true}
	      ,{field:'state', width:120, title: '是否审核',align:'center',sort: true,templet: '#switchTpl', unresize: true}
	      ,{field:'action', width:120, title: '操作',align:'center',templet:formatAction}
	    ]]
	    ,page: true
	  });
	//监听审核操作
	form.on('switch(hotSwitch)', function(obj){
	  	$.post("/admin/comment/updateCommentState",{"cid":this.name,"state":obj.elem.checked},function(result){
	  		if(result.success){
	  			layer.msg("执行成功！");
	  			table.reload("articleListTable",{});
	  		}else{
	  			layer.msg("执行失败，请联系管理员！");
	  		}
	  	});
	  });
});
 

//删除一个文章
function deleteOne(cid){
	layer.confirm('您确定要删除这条记录吗？', {
     title:"系统提示"
	  ,btn: ['确定','取消'] //按钮
	}, function(){
		layer.closeAll('dialog');
		window.location.href="/admin/comment/deleteComment/"+cid;
	}, function(){
	 
	});
}

//文章右侧的操作
function formatAction(d){
	return "<button class='layui-btn layui-btn-warm layui-btn-xs' onclick='deleteOne("+d.cid+")'><i class='layui-icon layui-icon-delete' ></i>删除</button>";
}

//查询
function search(){
	var s_name=$("#s_name").val();
	table.reload("commentList",{
		page:{
			curr:1
		}
		,where:{
			name:s_name
		}
	});
}

//审核的状态
function formatState(d){
	if(d.state==0){
		return "未审核";
	}else if(d.state==1){
		return "<font color=blue>审核通过</font>";
	}
}

</script>
	
#end